package com.nuanshui.heatedloan.controller.display.credit.third.party;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.controller.BaseController;
import com.nuanshui.heatedloan.credit.facade.AllinPayNotifyService;
import com.nuanshui.heatedloan.credit.pay.AllinPayResultNotify;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zss
 * @date 2017/7/26 13:51
 * @description
 * @Since
 */
@RequestMapping("credit/third/party")
@RestController
public class AllinPayNotifyController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(AllinPayNotifyController.class);

    @Reference(url = GlobalParam.CREDIT_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT, version = GlobalParam.CREDIT_DUBBO_SERVER_VERSION)
    private AllinPayNotifyService allinPayNotifyService;



    /**
     * 成功交易结果通知
     *
     * @param notify
     * @return
     */
    @RequestMapping("/successNotify")
    public String callBackTradeSuccessNotify(AllinPayResultNotify notify) {

        notify.setBIZTYPE(AllinPayResultNotify.BIZTYPE_SUUCESS);

        allinPayNotifyService.tradeSuccessNotify(notify);
        return success();
    }

    /**
     * 失败交易结果通知
     *
     * @param notify
     * @return
     */
    @RequestMapping("/failNotify")
    public String callBackTradeFailNotify(AllinPayResultNotify notify) {

        notify.setBIZTYPE(AllinPayResultNotify.BIZTYPE_FAIL);

        allinPayNotifyService.tradeFailNotify(notify);
        return success();
    }

    /**
     * 通联退票通知
     *
     * @param notify
     * @return
     */
    @RequestMapping("/refundNotify")
    public String callBackTradeRefundNotify(AllinPayResultNotify notify) {

        notify.setBIZTYPE(AllinPayResultNotify.BIZTYPE_REFUND);

        allinPayNotifyService.tradeRefundNotify(notify);
        return success();
    }
}
